package com.mf.page;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.mf.MyApplication;
import com.mf.interfaceTest.InterfaceTestMenu;
import com.mf.page.menu.MainMenuPage;
import com.mf.R;

import com.mf.mpos.pub.Controler;
import com.mf.mpos.pub.CommEnum.CONNECTMODE;

public class MainActivity extends Activity {
	private Button m_btnOk;
	private static String LOG_TAG = "main";
	
	SharedPreferences  config = null;	
	CONNECTMODE getMode(){
		int connectmode = config.getInt("CONNECTMODE", 0);		
		CONNECTMODE mode = CONNECTMODE.values()[connectmode];
		return mode;
	}
	
	private static int m_init = 0;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_main);
		m_btnOk = (Button)this.findViewById(R.id.btnOk);
		m_btnOk.setOnClickListener(OnBtnClickListener);
		m_btnOk.setFocusableInTouchMode(true);
		m_btnOk.requestFocus();
		
		
		Log.i(LOG_TAG, "app start");
		if(m_init == 0){
			m_init = 1;
			InterfaceTestMenu.Instance().init(this);
		}
		
		config = getSharedPreferences("config", 1);
		CONNECTMODE mode = getMode();
		Controler.Init(this,mode);
		
		//Controler.test(this, "00:15:83:0C:BF:EB" );
		//显示菜单界面
		MainMenuPage.ShowMenu(MainActivity.this , "应用主菜单");
	}
	
	
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub	
		Controler.Destory();
		super.onDestroy();	
		System.exit(0);
	}


	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		if( requestCode == 0)
		{//登录页面退出
			this.finish();			
		}
	}


	Button.OnClickListener OnBtnClickListener = new Button.OnClickListener(){
    	@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
    		if(v.getId() == R.id.btnOk){
    			//点击界面按钮进入菜单
    			MainMenuPage.ShowMenu(MainActivity.this, "应用主菜单");
    		}
		}
    };
}
